package webapp;

import java.util.ArrayList;
import java.util.List;

import mda.type.IDtoType;
import mda.type.IEntityType;
import mda.type.IServiceType;
import flca.mda.codegen.data.ITemplate;
import flca.mda.codegen.data.Template;
import flca.mda.codegen.data.TemplateMergeStrategy;

public class FlexConstants implements TemplatesConstBase {
	
	public static final String CARTRIDGE_NAME = "webapp-flex";
	
	protected static final String Frontend = LE + WebappConstants.FRONTEND_FLEX + RI;

	public Tid[] getTemplates() {
		return new Tid[] { Tid.FLEX_ENTITY, Tid.FLEX_SEARCH_DTO, Tid.FLEX_DTO, Tid.FLEX_ENTITY_MOCK,
				Tid.FLEX_ENTITY_MODEL, Tid.FLEX_DETAIL_FORM, Tid.FLEX_DETAIL_CTRL, Tid.FLEX_MAINT_CTRL,
				Tid.FLEX_MAINT_FORM, Tid.FLEX_VIEW_STACK, Tid.FLEX_SEARCH_CTRL, Tid.FLEX_SEARCH_FORM, Tid.FLEX_SERVICE,
				Tid.FLEX_SERVICE_FACT, Tid.FLEX_SERVICE_IMPL, Tid.FLEX_SERVICE_MOCK, Tid.FLEX_ENUM, };
	}

	private static List<ITemplate> allTemplates;
	
	public FlexConstants() {
		super();
		if (allTemplates == null) {
			allTemplates = makeTemplates();
		}
	}

	@Override
	public List<ITemplate> getAllTemplates() {
		return allTemplates;
	}

	public List<ITemplate> makeTemplates() {
		List<ITemplate> result = new ArrayList<ITemplate>();
		
		result.add(makeTemplate_FLEX_ENTITY());
		result.add(makeTemplate_FLEX_SEARCH_DTO());
		result.add(makeTemplate_FLEX_DTO());
		result.add(makeTemplate_FLEX_ENTITY_MOCK());
		result.add(makeTemplate_FLEX_ENTITY_MODEL());
		result.add(makeTemplate_FLEX_DETAIL_FORM());
		result.add(makeTemplate_FLEX_DETAIL_CTRL());
		result.add(makeTemplate_FLEX_MAINT_CTRL());
		result.add(makeTemplate_FLEX_MAINT_FORM());
		result.add(makeTemplate_FLEX_VIEW_STACK());
		result.add(makeTemplate_FLEX_SEARCH_CTRL());
		result.add(makeTemplate_FLEX_SEARCH_FORM());
		result.add(makeTemplate_FLEX_SERVICE());
		result.add(makeTemplate_FLEX_SERVICE_FACT());
		result.add(makeTemplate_FLEX_SERVICE_IMPL());
		result.add(makeTemplate_FLEX_SERVICE_MOCK());
		result.add(makeTemplate_FLEX_ENUM());
		
		return result;
	}
	
	private ITemplate makeTemplate_FLEX_ENTITY() {
		Template r = new Template();
		r.setName(Tid.FLEX_ENTITY.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3EntityAS.class.getName());
		r.setJetPath("/frontend/flex3/EntityAs.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SEARCH_DTO() {
		Template r = new Template();
		r.setName(Tid.FLEX_SEARCH_DTO.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("Search<%=CLASSNAME%>Dto");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3SearchDtoAS.class.getName());
		r.setJetPath("/frontend/flex3/SearchDtoAs.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_DTO() {
		Template r = new Template();
		r.setName(Tid.FLEX_DTO.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3DtoAS.class.getName());
		r.setJetPath("/frontend/flex3/DtoAs.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_ENTITY_MOCK() {
		Template r = new Template();
		r.setName(Tid.FLEX_ENTITY_MOCK.name());
		r.setPackage("<%=PACKAGE%>.mock");
		r.setClassname("<%=CLASSNAME%>Mock");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3EntityASMock.class.getName());
		r.setJetPath("/frontend/flex3/EntityASMock.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_ENTITY_MODEL() {
		Template r = new Template();
		r.setName(Tid.FLEX_ENTITY_MODEL.name());
		r.setPackage("<%=PACKAGE%>.util");
		r.setClassname("<%=CLASSNAME%>Model");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3ModelAS.class.getName());
		r.setJetPath("/frontend/flex3/ModelAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_DETAIL_FORM() {
		Template r = new Template();
		r.setName(Tid.FLEX_DETAIL_FORM.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>DetailForm");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".mxml");
		r.setGeneratorFqn(frontend.flex3.Flex3DetailForm.class.getName());
		r.setJetPath("/frontend/flex3/DetailForm.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_DETAIL_CTRL() {
		Template r = new Template();
		r.setName(Tid.FLEX_DETAIL_CTRL.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>DetailCtrl");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3DetailCtrl.class.getName());
		r.setJetPath("/frontend/flex3/DetailCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_MAINT_CTRL() {
		Template r = new Template();
		r.setName(Tid.FLEX_MAINT_CTRL.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>MaintCtrl");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3MaintCtrl.class.getName());
		r.setJetPath("/frontend/flex3/MaintCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_MAINT_FORM() {
		Template r = new Template();
		r.setName(Tid.FLEX_MAINT_FORM.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>MaintForm");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".mxml");
		r.setGeneratorFqn(frontend.flex3.Flex3MaintForm.class.getName());
		r.setJetPath("/frontend/flex3/MaintForm.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_VIEW_STACK() {
		Template r = new Template();
		r.setName(Tid.FLEX_VIEW_STACK.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>ViewStack");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3ViewstackCtr.class.getName());
		r.setJetPath("/frontend/flex3/ViewStackCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SEARCH_CTRL() {
		Template r = new Template();
		r.setName(Tid.FLEX_SEARCH_CTRL.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>SearchCtrl");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3SearchCtrl.class.getName());
		r.setJetPath("/frontend/flex3/SearchCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SEARCH_FORM() {
		Template r = new Template();
		r.setName(Tid.FLEX_SEARCH_FORM.name());
		r.setPackage("<%=PACKAGE%>.form");
		r.setClassname("<%=CLASSNAME%>SearchForm");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".mxml");
		r.setGeneratorFqn(frontend.flex3.Flex3SearchForm.class.getName());
		r.setJetPath("/frontend/flex3/SearchForm.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SERVICE() {
		Template r = new Template();
		r.setName(Tid.FLEX_SERVICE.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3Service.class.getName());
		r.setJetPath("/frontend/flex3/ServiceAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SERVICE_FACT() {
		Template r = new Template();
		r.setName(Tid.FLEX_SERVICE_FACT.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Fact");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3ServiceFactoryAS.class.getName());
		r.setJetPath("/frontend/flex3/ServiceFactoryAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SERVICE_IMPL() {
		Template r = new Template();
		r.setName(Tid.FLEX_SERVICE_IMPL.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Impl");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3ServiceImpleAS.class.getName());
		r.setJetPath("/frontend/flex3/ServiceImplAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_SERVICE_MOCK() {
		Template r = new Template();
		r.setName(Tid.FLEX_SERVICE_MOCK.name());
		r.setPackage("<%=PACKAGE%>.mock");
		r.setClassname("<%=CLASSNAME%>Mock");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3ServiceImplMockAS.class.getName());
		r.setJetPath("/frontend/flex3/ServiceImplMockAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_FLEX_ENUM() {
		Template r = new Template();
		r.setName(Tid.FLEX_ENUM.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir("<%=FrontendFlex%>/<%=src-gen%>");
		r.setFileExtension(".as");
		r.setGeneratorFqn(frontend.flex3.Flex3Enum.class.getName());
		r.setJetPath("/frontend/flex3/EnumAS.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {Enum.class,});
		r.setRank(5);
		return r;
	}

	public static ITemplate getTemplate(Tid aTid) {
		if (allTemplates == null) {
			new FlexConstants();
		}

		for (ITemplate t : allTemplates) {
			if (t.getName().equals(aTid.name())) {
				return t;
			}
		}
		return null;
	}


	
}
